package com.claimSettlement.controller;

import com.claimSettlement.pojo.Warranty;
import com.claimSettlement.service.WarrantyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 保单控制层
 */
@RestController
@CrossOrigin
@RequestMapping("/warranty")
public class WarrantyController {
    @Autowired
    WarrantyService service;

    @RequestMapping("/getWarrantyAll")
    public PageInfo<Warranty> getWarrantyAll(int page){
        PageHelper.startPage(page,4);
        List<Warranty> list=service.getWarrantyAll();
        PageInfo<Warranty> pageInfo = new PageInfo<Warranty>(list,4);
        return pageInfo;
    }

    @RequestMapping(value = "/updateWarranty", method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public int updateWarranty(@RequestBody Warranty warranty){
        return service.updateWarranty(warranty);
    }

    @RequestMapping("/updWarrantyState")
    public int updWarrantyState(String warrantyState, String warrantyId) {
        return service.updWarrantyState(warrantyState, warrantyId);
    }
    @RequestMapping(value = "/addWarranty", method = RequestMethod.POST)
    public int addWarranty(@RequestBody Warranty warranty) {
        return service.addWarranty(warranty);
    }

    @RequestMapping("/getWarrantyOne")
    public Warranty getWarrantyOne(String warrantyId) {
        return service.getWarrantyOne(warrantyId);
    }

    @RequestMapping("/getWarrantyId")
    public  PageInfo<Warranty> getWarrantyId(String warrantyId, String recognizeeName, String plateNumber, String frameId,int page) {
        PageHelper.startPage(page,4);
        List<Warranty> list=service.getWarrantyId(warrantyId, recognizeeName, plateNumber, frameId);
        PageInfo<Warranty> pageInfo = new PageInfo<Warranty>(list,4);
        return pageInfo;
    }

    @RequestMapping("/getWarrantyAll2")
    public  List<Warranty> getWarrantyAll2(){
        List<Warranty> list=service.getWarrantyAll2();
        return list;
    }
    @RequestMapping("/getWarrantyNow")
    public String getWarrantyNow() {
        return service.getWarrantyNow();
    }
    @RequestMapping("/selectRisk")
    public List<Integer> selectRisk(String warrantyId) {
        return service.selectRisk(warrantyId);
    }
    @RequestMapping("/insertInsure")
    public int insertInsure(String warrantyId, int riskTypeId) {
        return service.insertInsure(warrantyId, riskTypeId);
    }
    @RequestMapping("/updatePremiumTotal")
    public int updatePremiumTotal(double premiumTotal, String warrantyId) {
        int count=service.updatePremiumTotal(premiumTotal, warrantyId);
        return count;
    }

    @RequestMapping("/getCaseChepai")
    public List<String> getCaseChepai(String caseId){
        return service.getCaseChepai(caseId);
    }
    @RequestMapping("/getWarrantyCount")
    public int getWarrantyCount(String recognizeeId,String plateNumber) {
        return service.getWarrantyCount(recognizeeId,plateNumber);
    }
}
